//
//  FriendTopView.m
//  YiXiProject
//
//  Created by iMac on 2019/7/25.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "FriendTopView.h"

@implementation FriendTopView

-(UIButton *)leftFriBtn
{
    if(!_leftFriBtn)
    {
        _leftFriBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftFriBtn.tag = 100;
        [_leftFriBtn setImage:[UIImage imageNamed:@"friBack"] forState:UIControlStateNormal];
        [_leftFriBtn addTarget:self action:@selector(clickFriendBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftFriBtn;
}

-(UIImageView *)friMessageImg
{
    if(!_friMessageImg)
    {
        _friMessageImg = [[UIImageView alloc] init];
        _friMessageImg.image = [UIImage imageNamed:@"friTitleimg"];
    }
    return _friMessageImg;
}

-(UIButton *)messageBtn
{
    if(!_messageBtn)
    {
        _messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _messageBtn.tag = 101;
        [_messageBtn setTitle:@"Messages" forState:UIControlStateNormal];
        [_messageBtn setTitleColor:GrayColor forState:UIControlStateNormal];
        [_messageBtn setTitleColor:ColorAlphe(178,34,34, 1) forState:UIControlStateSelected];
        _messageBtn.titleLabel.font = HeiTiFont(20);
        _messageBtn.selected = YES;
        [_messageBtn addTarget:self action:@selector(clickFriendBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _messageBtn;
}

-(UIButton *)feedBtn
{
    if(!_feedBtn)
    {
        _feedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _feedBtn.tag = 102;
        [_feedBtn setTitle:@"Feed" forState:UIControlStateNormal];
        [_feedBtn setTitleColor:GrayColor forState:UIControlStateNormal];
        [_feedBtn setTitleColor:ColorAlphe(178,34,34, 1) forState:UIControlStateSelected];
        _feedBtn.titleLabel.font = HeiTiFont(20);
        [_feedBtn addTarget:self action:@selector(clickFriendBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _feedBtn;
}

-(UILabel *)line
{
    if(!_line)
    {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = Color(0.8, 0.8, 0.8, 1);
    }
    return _line;
}


-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.leftFriBtn];
        [self addSubview:self.friMessageImg];
        [self addSubview:self.messageBtn];
        [self addSubview:self.line];
        [self addSubview:self.feedBtn];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _leftFriBtn.sd_layout.leftSpaceToView(self, 20).bottomSpaceToView(self, 90).widthIs(40).heightIs(40);
    _friMessageImg.sd_layout.leftSpaceToView(self, SCREEN_WIDTH/2-25).bottomSpaceToView(self, 87).widthIs(50).heightIs(45);
    
    _messageBtn.sd_layout.leftSpaceToView(self, 0).bottomSpaceToView(self, 0).widthIs(SCREEN_WIDTH/2).topSpaceToView(_friMessageImg, 0);
    _line.sd_layout.leftSpaceToView(_messageBtn, 0).bottomSpaceToView(self, 25).widthIs(1).topSpaceToView(_friMessageImg, 25);
    _feedBtn.sd_layout.leftSpaceToView(_line, 0).bottomSpaceToView(self, 0).rightSpaceToView(self, 0).topSpaceToView(_friMessageImg, 0);
}

-(void)clickFriendBtn:(UIButton *)btn
{
    btn.selected = NO;
    
    if (btn != _messageBtn) {

        _messageBtn.selected = NO;

        _messageBtn = btn;

    } 

    _messageBtn.selected = YES;
    
    
    if([_delegate respondsToSelector:@selector(clickFriendButtonTag:)])
    {
        [_delegate clickFriendButtonTag:btn.tag];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
